home *** CD-ROM | disk | FTP | other *** search
/ BCI NET / BCI NET Dec 94.iso / archives / programming / libraries / newiff.lha / NewIFF / NewIFF39.lha / newiff39 / iffp / ilbm.h < prev    next >
C/C++ Source or Header  |  1993-09-28  |  11KB  |  318 lines

  1. /* 
  2.  *
  3.  * ilbm.h:    Definitions for IFFParse ILBM reader.
  4.  *
  5.  * 5/92
  6.  * 39.1 - 7/92 - added setcolors, interface change for loadcmap
  7.  * 39.5 - 11/92 - get rid of BytesPerRow macro which duplicated RowBytes
  8.  *                AND conflicted with a system structure member name.
  9.  *          Changed "BitsPerRow" macro to "RowBits" to match.
  10.  *                Also unconditionalized extern of GfxBase and IntuitionBase
  11.  * 39.10 - 8/93 - add comment about MAXAMDEPTH
  12.  * 39.11 - 9/93 - add NoCenter arg to clipit
  13.  */
  14.  
  15. #ifndef IFFP_ILBM_H
  16. #define IFFP_ILBM_H
  17.  
  18. #ifndef IFFP_IFF_H
  19. #include "iffp/iff.h"
  20. #endif
  21.  
  22. #ifndef INTUITION_INTUITION_H
  23. #include <intuition/intuition.h>
  24. #endif
  25. #ifndef GRAPHICS_VIDEOCONTROL_H
  26. #include <graphics/videocontrol.h>
  27. #endif
  28.  
  29. #ifndef NO_PROTOS
  30. #include <clib/graphics_protos.h>
  31. #include <clib/intuition_protos.h>
  32. #include <clib/alib_protos.h>
  33. #endif
  34.  
  35. extern struct Library *IntuitionBase;
  36. extern struct Library *GfxBase;
  37.  
  38. #ifndef NO_SAS_PRAGMAS
  39. #include <pragmas/intuition_pragmas.h>
  40. #include <pragmas/graphics_pragmas.h>
  41. #endif
  42.  
  43. /*  IFF types we may encounter  */
  44. #define    ID_ILBM        MAKE_ID('I','L','B','M')
  45.  
  46. /* ILBM Chunk ID's we may encounter
  47.  * (see iffp/iff.h for some other generic chunks)
  48.  */
  49. #define    ID_BMHD        MAKE_ID('B','M','H','D')
  50. #define    ID_CMAP        MAKE_ID('C','M','A','P')
  51. #define    ID_CRNG        MAKE_ID('C','R','N','G')
  52. #define    ID_CCRT        MAKE_ID('C','C','R','T')
  53. #define    ID_GRAB        MAKE_ID('G','R','A','B')
  54. #define    ID_SPRT        MAKE_ID('S','P','R','T')
  55. #define    ID_DEST        MAKE_ID('D','E','S','T')
  56. #define    ID_CAMG        MAKE_ID('C','A','M','G')
  57.  
  58. /* Use this constant instead of sizeof(ColorRegister).
  59.  * ONLY VALID FOR size of color register AS STORED in ILBM.CMAP
  60.  */
  61. #define sizeofColorRegister  3
  62.  
  63.  
  64. typedef WORD Color4;   /* Amiga RAM version of a color-register,
  65.           * with 4 bits each RGB in low 12 bits.*/
  66.  
  67. typedef struct {
  68.     ULONG    r;
  69.     ULONG    g;
  70.     ULONG    b;
  71.     } Color32;
  72.  
  73. /* Maximum number of bitplanes storable in BitMap structure
  74.  * Used only for OS < V37 by screen.c maxdisplaydepth(ULONG displayid)
  75.  */
  76. #define MAXAMDEPTH 8
  77.  
  78. /* Use ViewPort->ColorMap.Count instead 
  79. #define MAXAMCOLORREG 32
  80. */
  81.  
  82. /* Maximum planes this code can save */
  83. #define MAXSAVEDEPTH 24
  84.  
  85. /* Convert image width to even number of BytesPerRow for ILBM save.
  86.  * Do NOT use this macro to determine the actual number of bytes per row
  87.  * in an Amiga BitMap.  Use BitMap->BytesPerRow for scan-line modulo.
  88.  * Use your screen or viewport width to determine width. Or under
  89.  * V39, use GetBitMapAttr().
  90.  */
  91. #define RowBytes(w)    ((((w) + 15) >> 4) << 1)
  92. #define RowBits(w)    ((((w) + 15) >> 4) << 4)
  93.  
  94. /* Flags that should be masked out of old 16-bit CAMG before save or use.
  95.  * Note that 32-bit mode id (non-zero high word) bits should not be twiddled
  96.  */
  97. #define BADFLAGS  (SPRITES|VP_HIDE|GENLOCK_AUDIO|GENLOCK_VIDEO)
  98. #define OLDCAMGMASK  (~BADFLAGS)
  99.  
  100.  
  101. /*  Masking techniques  */
  102. #define    mskNone            0
  103. #define    mskHasMask        1
  104. #define    mskHasTransparentColor    2
  105. #define    mskLasso        3
  106.  
  107. /* We plan to define this value, to mean that the BMHD.transparentColor
  108.  * variable contains a count of alpha channel planes which are stored
  109.  * in the BODY AFTER the image planes.  As always, the count of
  110.  * masking/alpha planes is not included in BMHD.nPlanes.
  111.  * If you have any comments or input, contact Chris Ludwig (CATS US).
  112.  */
  113. #define    mskHasAlpha        4
  114.  
  115.  
  116. /*  Compression techniques  */
  117. #define    cmpNone            0
  118. #define    cmpByteRun1        1
  119.  
  120.  
  121.  
  122. /* ---------- BitMapHeader ---------------------------------------------*/
  123. /*  Required Bitmap header (BMHD) structure describes an ILBM */
  124. typedef struct {
  125.     UWORD    w, h;        /* Width, height in pixels */
  126.     WORD    x, y;        /* x, y position for this bitmap  */
  127.     UBYTE    nPlanes;    /* # of planes (not including mask) */
  128.     UBYTE    masking;    /* a masking technique listed above */
  129.     UBYTE    compression;    /* cmpNone or cmpByteRun1 */
  130.     UBYTE    flags;        /* as defined or approved by Commodore */
  131.     UWORD    transparentColor;
  132.     UBYTE    xAspect, yAspect;
  133.     WORD    pageWidth, pageHeight;
  134. } BitMapHeader;
  135.  
  136. /* BMHD flags */
  137.  
  138. /* Advisory that 8 significant bits-per-gun have been stored in CMAP
  139.  * i.e. that the CMAP is definitely not 4-bit values shifted left.
  140.  * This bit will disable nibble examination by color loading routine.
  141.  */
  142. #define BMHDB_CMAPOK    7
  143. #define BMHDF_CMAPOK    (1 << BMHDB_CMAPOK)
  144.  
  145.  
  146. /* ---------- ColorRegister --------------------------------------------*/
  147. /* A CMAP chunk is a packed array of ColorRegisters (3 bytes each). */
  148. typedef struct {
  149.     UBYTE red, green, blue;   /* MUST be UBYTEs so ">> 4" won't sign extend.*/
  150.     } ColorRegister;
  151.  
  152. /* ---------- Point2D --------------------------------------------------*/
  153. /* A Point2D is stored in a GRAB chunk. */
  154. typedef struct {
  155.     WORD x, y;      /* coordinates (pixels) */
  156.     } Point2D;
  157.  
  158. /* ---------- DestMerge ------------------------------------------------*/
  159. /* A DestMerge is stored in a DEST chunk. */
  160. typedef struct {
  161.     UBYTE depth;   /* # bitplanes in the original source */
  162.     UBYTE pad1;      /* UNUSED; for consistency store 0 here */
  163.     UWORD planePick;   /* how to scatter source bitplanes into destination */
  164.     UWORD planeOnOff;   /* default bitplane data for planePick */
  165.     UWORD planeMask;   /* selects which bitplanes to store into */
  166.     } DestMerge;
  167.  
  168. /* ---------- SpritePrecedence -----------------------------------------*/
  169. /* A SpritePrecedence is stored in a SPRT chunk. */
  170. typedef UWORD SpritePrecedence;
  171.  
  172. /* ---------- Camg Amiga Viewport Mode Display ID ----------------------*/
  173. /* The CAMG chunk is used to store the Amiga display mode in which
  174.  * an ILBM is meant to be displayed.  This is very important, especially
  175.  * for special display modes such as HAM and HALFBRITE where the
  176.  * pixels are interpreted differently.
  177.  * Under V37 and higher, store a 32-bit Amiga DisplayID (aka. ModeID)
  178.  * in the ULONG ViewModes CAMG variable (from GetVPModeID(viewport)).
  179.  * Pre-V37, instead store the 16-bit viewport->Modes.
  180.  * See the current IFF manual for information on screening for bad CAMG
  181.  * chunks when interpreting a CAMG as a 32-bit DisplayID or 16-bit ViewMode.
  182.  * The chunk's content is declared as a ULONG.
  183.  */
  184. typedef struct {
  185.    ULONG ViewModes;
  186.    } CamgChunk;
  187.  
  188. /* ---------- CRange cycling chunk -------------------------------------*/
  189. #define RNG_NORATE  36   /* Dpaint uses this rate to mean non-active */
  190. /* A CRange is store in a CRNG chunk. */
  191. typedef struct {
  192.     WORD  pad1;              /* reserved for future use; store 0 here */
  193.     WORD  rate;      /* 60/sec=16384, 30/sec=8192, 1/sec=16384/60=273 */
  194.     WORD  active;     /* bit0 set = active, bit 1 set = reverse */
  195.     UBYTE low, high;   /* lower and upper color registers selected */
  196.     } CRange;
  197.  
  198. /* ---------- Ccrt (Graphicraft) cycling chunk -------------------------*/
  199. /* A Ccrt is stored in a CCRT chunk. */
  200. typedef struct {
  201.    WORD  direction;  /* 0=don't cycle, 1=forward, -1=backwards */
  202.    UBYTE start;      /* range lower */
  203.    UBYTE end;        /* range upper */
  204.    LONG  seconds;    /* seconds between cycling */
  205.    LONG  microseconds; /* msecs between cycling */
  206.    WORD  pad;        /* future exp - store 0 here */
  207.    } CcrtChunk;
  208.  
  209. /* If you are writing all of your chunks by hand,
  210.  * you can use these macros for these simple chunks.
  211.  */
  212. #define putbmhd(iff, bmHdr)  \
  213.     PutCk(iff, ID_BMHD, sizeof(BitMapHeader), (BYTE *)bmHdr)
  214. #define putgrab(iff, point2D)  \
  215.     PutCk(iff, ID_GRAB, sizeof(Point2D), (BYTE *)point2D)
  216. #define putdest(iff, destMerge)  \
  217.     PutCk(iff, ID_DEST, sizeof(DestMerge), (BYTE *)destMerge)
  218. #define putsprt(iff, spritePrec)  \
  219.     PutCk(iff, ID_SPRT, sizeof(SpritePrecedence), (BYTE *)spritePrec)
  220. #define putcamg(iff, camg)  \
  221.     PutCk(iff, ID_CAMG, sizeof(CamgChunk),(BYTE *)camg)
  222. #define putcrng(iff, crng)  \
  223.     PutCk(iff, ID_CRNG, sizeof(CRange),(BYTE *)crng)
  224. #define putccrt(iff, ccrt)  \
  225.     PutCk(iff, ID_CCRT, sizeof(CcrtChunk),(BYTE *)ccrt)
  226.  
  227. #ifndef NO_PROTOS
  228. /* unpacker.c */
  229. BOOL unpackrow(BYTE **pSource, BYTE **pDest, WORD srcBytes0, WORD dstBytes0);
  230.  
  231. /* packer.c */
  232. LONG packrow(BYTE **pSource, BYTE **pDest, LONG rowSize);
  233.  
  234. /* ilbmr.c  ILBM reader routines */
  235. LONG loadbody(struct IFFHandle *iff, struct BitMap *bitmap,
  236.         BitMapHeader *bmhd);
  237. LONG loadbody2(struct IFFHandle *iff, struct BitMap *bitmap, 
  238.         BYTE *mask, BitMapHeader *bmhd, 
  239.         BYTE *buffer, ULONG bufsize);
  240. LONG loadcmap(struct ILBMInfo *ilbm);
  241. LONG getcolors(struct ILBMInfo *ilbm);
  242. LONG setcolors(struct ILBMInfo *ilbm, struct ViewPort *vp);
  243. void freecolors(struct ILBMInfo *ilbm);
  244. LONG alloccolortable(struct ILBMInfo *ilbm);
  245. ULONG getcamg(struct ILBMInfo *ilbm);
  246.  
  247. /* ilbmw.c  ILBM writer routines */
  248. long initbmhd(BitMapHeader *bmhd, struct BitMap *bitmap,
  249.               WORD masking, WORD compression, WORD transparentColor,
  250.               WORD width, WORD height, WORD pageWidth, WORD pageHeight,
  251.               ULONG modeid);
  252. long putcmap(struct IFFHandle *iff,APTR colortable,UWORD ncolors,UWORD bitspergun);
  253. long putbody(struct IFFHandle *iff, struct BitMap *bitmap,
  254.         BYTE *mask, BitMapHeader *bmHdr,
  255.         BYTE *buffer, LONG bufsize);
  256.  
  257. /* getdisplay.c (used to load a display) */
  258. LONG showilbm(struct ILBMInfo *ilbm, UBYTE *filename);
  259. BOOL unshowilbm(struct ILBMInfo *ilbm);
  260. LONG createdisplay(struct ILBMInfo *);
  261. BOOL deletedisplay(struct ILBMInfo *);
  262. LONG getdisplay(struct ILBMInfo *);
  263. BOOL freedisplay(struct ILBMInfo *);
  264.  
  265. /* getbitmap.c (used if just loading brush or bitmap) */
  266. LONG createbrush(struct ILBMInfo *);
  267. void deletebrush(struct ILBMInfo *);
  268. LONG getbitmap(struct ILBMInfo *);
  269. void freebitmap(struct ILBMInfo *);
  270.  
  271. /* screen.c (opens 1.3 or 2.0 screen) */
  272. struct Screen *openidscreen(struct ILBMInfo *,SHORT,SHORT,SHORT,ULONG);
  273. struct Window *opendisplay(struct ILBMInfo *,SHORT,SHORT,SHORT,ULONG);
  274. ULONG  modefallback(ULONG, SHORT, SHORT, SHORT);
  275. void clipit(SHORT wide, SHORT high, struct Rectangle *spos,
  276.     struct Rectangle *dclip, struct Rectangle *txto,
  277.     struct Rectangle *stdo,struct Rectangle *maxo,
  278.     struct Rectangle * uclip,
  279.     BOOL NoCenter);
  280. BOOL closedisplay(struct ILBMInfo *ilbm);
  281. UWORD maxdisplaydepth(ULONG displayid);
  282.  
  283. /* loadilbm.c */
  284. LONG loadbrush(struct ILBMInfo *ilbm, UBYTE *filename);
  285. void unloadbrush(struct ILBMInfo *ilbm);
  286.  
  287. LONG queryilbm(struct ILBMInfo *ilbm, UBYTE *filename);
  288.  
  289. LONG loadilbm(struct ILBMInfo *ilbm, UBYTE *filename);
  290. void unloadilbm(struct ILBMInfo *ilbm);
  291.  
  292. /* saveilbm.c */
  293. LONG screensave(struct ILBMInfo *ilbm,
  294.             struct Screen *scr,
  295.             struct Chunk *chunklist1, struct Chunk *chunklist2,
  296.             UBYTE *filename);
  297.  
  298. LONG saveilbm(struct ILBMInfo *ilbm,
  299.         struct BitMap *bitmap, ULONG modeid,
  300.         WORD width, WORD height, WORD pagewidth, WORD pageheight,
  301.         APTR colortable, UWORD count, UWORD bitspergun,
  302.                 WORD masking, WORD transparentColor,
  303.         struct Chunk *chunklist1, struct Chunk *chunklist2,
  304.         UBYTE *filename);
  305.  
  306.  
  307. /* screendump.c (print screen or brush) */
  308. int screendump(struct Screen *scr,
  309.      UWORD srcx, UWORD srcy, UWORD srcw, UWORD srch,
  310.      LONG destcols, UWORD special);
  311.  
  312. /* bmprintc.c (write C source for ILBM) */
  313. void BMPrintCRep(struct BitMap *bm, FILE *fp, UBYTE *name, UBYTE *fmt);  
  314.  
  315. #endif /* NO_PROTOS */
  316.  
  317. #endif /* IFFP_ILBM_H */
  318.